﻿using NFine.Code;
using NFine.Code.Text;
using NFine.Data;
using NFine.Domain._03_Entity.Weixin;
using NFine.Domain._04_IRepository.Weixin;
using NFine.Repository.Weixin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NFine.Application._02_Weixin
{
    public class UserInfoApp
    {
        private IUserInfoRepository service = new UserInfoRepository();

        private Log logger = LogFactory.GetLogger("NFine.Application.Biz.WechatInfoApp");

        public UserInfoEntity GetUserInfoByUniond(string unionid)
        {
           return service.FindEntity(x=>x.WECHATACCOUNT== unionid);
        }

        public bool insert(UserInfoEntity entity,string oid)
        {
            List<string> allUserNumber = service.IQueryable().Select(a => a.USERNUMBER).ToList();
            entity.USERNUMBER = TextUtil.getStringNumber(allUserNumber);
            if (service.Insert(entity) > 0)
            {
                //插入用户动态信息
                UserInfoEntity userInfo = GetUserInfoByUniond(entity.WECHATACCOUNT);
                this.service.InsertUserDynamic(userInfo);
                this.service.InsertUserOpenID(Convert.ToInt32(userInfo.USERNUMBER), userInfo.WECHATACCOUNT, oid);

            }
            return true;
        }


        public void checkuseropenid(UserInfoEntity userinfo,string oid)
        {
            service.checkuseropenid(userinfo, oid);
        }

    }
}
